<?php
namespace Login\Controller;

use Think\Controller;

class IndexController extends Controller
{

    public function index()
    {
        //isLogin();
       
        //var_dump( verify());exit();
        if (!is_null(cookie("session_id"))){
        session("session_id",cookie("session_id"));
        session("username",cookie("username"));
        }
        toAdmin();
        $this->display();
    }
    
    public function verify()
    {
          $Verify = new \Think\Verify();
    $Verify->fontSize = 18;
    $Verify->length   = 4;
    $Verify->useNoise = false;
//    $Verify->codeSet = '0123456789';
    $Verify->imageW = 130;
    $Verify->imageH = 50;
    //$Verify->expire = 600;
    $Verify->entry();
    }

    public function login()
    {
        $ver = $_POST['ver'];
        if(!check_verify($ver)){
            //var_dump(check_verify());exit();
           // $this->error("亲，验证码输错了哦！",$this->site_url,9);
           // verify();
           echo "亲，验证码输错了哦！";
           
           return false;
        }
        
        $user = $_POST['user'];
        // var_dump($user);exit();
        $pwd = md5($_POST['pwd']);
        // var_dump($pwd);exit();
         //session(array('mysession'=>'session_id','expire'=>3600));
        $rem = $_POST['rem'];
        //var_dump($rem);exit();
        //var_dump(session_id());exit();
        $where['username'] = array(
            'eq',
            $user
        );
        $where['password'] = array(
            'eq',
            $pwd
        );
        $Admin = M('Admin');
        $list = $Admin->where($where)->find();
        // var_dump(count($list));exit();
        if (count($list) > 0) {
            
            if ($rem=="true"){
               // session_set_cookie_params(3600*24*7);
               // session_start;
               //var_dump($rem);exit();
                //session_destroy();//cookie('name','value',3600);
//                 session(array('expire' => '1800'));
//                 session('[start]');
                cookie('session_id',session_id(),3600*12);
                cookie('username',$user,3600*12);
                //session('expire',1000);
            }
            session('session_id',session_id());
            session('username',$user);
            //session(null);
             echo 1;
            // header("Location:".__ROOT__);
        } else {
            echo '用户名密码错误';
        }
        // $this->display();
    }

    
}